home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.052 < prev    next >
Encoding:
Text File  |  1992-07-15  |  8.0 KB  |  194 lines  |  [TEXT/GEOL]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5. Apple IIgs
  6. #52: Loading and Special Memory
  7.  
  8. Revised by: Dave Lyons                                               May 1992
  9. Written by: Eric Soldan                                          January 1989
  10.  
  11. This Technical Note discusses strategies for preventing applications from
  12. loading into special memory.
  13.  
  14. CHANGES SINCE JULY 1989:  Noted that the System 6 Loader always tries
  15. non-special memory before special memory.
  16. _____________________________________________________________________________
  17.  
  18.  
  19. The System 6.0 Loader always tries to load segments into non-special memory
  20. before allowing them to load into special memory.  The rest of this Note is
  21. useful if your application does not require System 6, or if you need an
  22. example of an initialization segment.
  23.  
  24. The System Loader loads your application starting at the lowest memory
  25. location possible.  If you allow your program to load into special memory, the
  26. Loader first tries bank $01.  If your program cannot load into special memory,
  27. it starts at bank $02.  Either way, the Loader progresses to higher banks, and
  28. eventually, it may even try loading into bank $E1, which contains the super
  29. hi-res screen.
  30.  
  31. The problem with allowing your application to load into special memory is that
  32. the super hi-res screen is part of special memory.  If you have a desktop
  33. application, part of your application may load into the super hi-res screen,
  34. and when you try to start QuickDraw II, it fails because the screen memory is
  35. already allocated.
  36.  
  37. When QuickDraw II fails because your program loaded into the SHR screen, it
  38. seems reasonable to assume that the Loader put your program there because it
  39. needed the RAM which special memory provides.  This logic seems to make sense,
  40. but it is not completely reliable.  The Loader (in System Software earlier
  41. than 6.0) tries to put your program into special memory before it tries
  42. purging dormant applications.  This means that the more programs that run from
  43. the Finder that set the GS/OS or ProDOS 16 "restartable from memory" bit, the
  44. more likely it is that the next application launched that can load into
  45. special memory will load into the super hi-res screen.
  46.  
  47. For this reason, it is important not to let your application load into special
  48. memory, or at least not load into the super hi-res screen.  If your
  49. application is not allowed to load into special memory, then the Loader will
  50. purge other dormant applications to make space for yours.  One way to
  51. accomplish this is when linking your application.  You can set the "no special
  52. memory" bit in the OMF KIND field of applications using OMF 2.0 or later, but
  53. this also prohibits your application from using bank $01.
  54.  
  55. Another way to avoid loading into the super hi-res screen is to have your
  56. initial segment allocate the super hi-res screen.  You can accomplish this by
  57. starting QuickDraw II in your initial segment, then the rest of your program
  58. cannot load into the already-allocated super hi-res screen.  This strategy
  59. could fail if the initial segment loaded into the super hi-res screen, but
  60. this is very unlikely and can be prevented by flagging the initial segment to
  61. only load into non-special memory.  You can do this by setting the "no special
  62. memory" bit in the KIND field only for the initial segment.
  63.  
  64. Here's an example of such an initial segment in MPW IIgs format:
  65.  
  66. ************************************************************************
  67. *
  68. * You may wish to do this stuff in the initial segment of your
  69. * application.  The initial segment should be set so that it does not
  70. * load into special memory, or else it is possible that it would load
  71. * into the super hi-res screen.  If this occurred, then QuickDraw II would
  72. * not be able to be started.
  73. *
  74. * Once QuickDraw II is started, the super hi-res screen is taken,
  75. * therefore the rest of the application can not load into it.  Therefore,
  76. * special memory is generally an acceptable place for the rest of the
  77. * application to load, since the special memory needed for the screen
  78. * is already taken.
  79. *
  80. * If the performance of your application would be adversely affected
  81. * by memory fragmentation, then you should also consider purging
  82. * other dormant applications and dormant tools, and then compacting
  83. * memory.  This will prevent fragmentation as much as possible
  84. * while your application is loading.  It also has the cost of longer
  85. * startup time since some tools may have to be reloaded.  This is the
  86. * only way to be sure that tools that you don't want are removed
  87. * from memory before the rest of your application tries to load
  88. * around them.
  89. *
  90. * The Finder is a dormant application when your application is
  91. * launched.  This will cause the Finder to be thrown out of memory,
  92. * and it will have to be reloaded when your application is quit.
  93. *
  94. ************************************************************************
  95.  
  96.                case on
  97.  
  98.                include 'e16.memory'
  99.                include 'm16.memory'
  100.                include 'm16.quickdraw'
  101.  
  102. screenMode     equ   $80
  103. AppMaxWidth    equ   160              ;Double this and your application
  104.                                       ;will print in BetterText mode.
  105. ******************
  106.  
  107. initialScreen  PROC
  108.  
  109. myID           equ   1                ;long
  110. zpagehndl      equ   myID+4           ;long
  111.  
  112. stkAfterLocals equ   zpagehndl+4
  113.  
  114. directReg      equ   stkAfterLocals
  115. retAddr        equ   directReg+2
  116. passedParms    equ   retAddr+3
  117.  
  118.                phd                    ;Set up stack frame.
  119.                tsc
  120.                sec
  121.                sbc   #stkAfterLocals-1
  122.                tcs
  123.                tcd
  124.                pha
  125.                _MMStartUp
  126.                pla
  127.                sta   myID             ;Get the userI
  128.                pha
  129.                _HLockAll              ;Lock down the rest of ourselves, in
  130.                                       ;case we are being restarted.  The
  131.                                       ;loader does not prelock down stuff,
  132.                                       ;so we would be disposing of the rest
  133.                                       ;of ourselves.
  134.  
  135.                pea   $1000
  136.                _PurgeAll              ;Purge other dormant applications.
  137.                                       ;This is optional.
  138.                pea  $4000
  139.                _PurgeAll              ;Purge dormant tools.
  140.                                       ;This is optional.
  141.  
  142.                _CompactMem            ;Clean up memory.  This is advised.
  143.  
  144.                pha                    ;Make direct space for QuickDraw.
  145.                pha
  146.                pea   $300>>16         ;Hi-byte of $300 address.
  147.                pea   $300
  148.                pei   myID
  149.                pea   attrLocked+attrFixed+attrPage+attrBank
  150.                lda   #0
  151.                pha
  152.                pha
  153.                _NewHandle
  154.                plx
  155.                stx   zpagehndl
  156.                plx
  157.                stx   zpagehndl+2
  158.                bcc   @a
  159.                ERRORDEATH 'Out of bank 0 memory'
  160.  
  161. @a             lda   zpagehndl
  162.                sta   >qdstarthndl     ;Used for disposing handle at shutdown.
  163.                txa
  164.                sta   >qdstarthndl+2
  165.                lda   [zpagehndl]      ;Start up QuickDraw.  This protects
  166.                pha                    ;screen RAM from the rest of the
  167.                pea   screenMode       ;application loading into it.
  168.                pea   AppMaxWidth
  169.                pei   myID
  170.                _QDStartUp
  171.                bcc   @b
  172.                ERRORDEATH 'Can''t start up QuickDraw'
  173. @b                                    ;Do title screen here.
  174.                tsc
  175.                clc
  176.                adc  #stkAfterLocals-1
  177.                tcs
  178.                pld
  179.                rtl
  180.  
  181. qdstarthndl    dc.l  0
  182.  
  183.                ENDP
  184.                END
  185.  
  186.  
  187. Further Reference:
  188. _____________________________________________________________________________
  189.  
  190.    o   GS/OS Reference, Volume I
  191.    o   MPW IIgs Tools Reference
  192.    o   APW Assembler Reference
  193.  
  194.